/*
 * Object.h
 *
 *  Created on: 2013-6-20
 *  Author: xnan
 */

#ifndef XNL_OBJECT_CLASS_H_
#define XNL_OBJECT_CLASS_H_

#include <cstdlib>
#include <stdexcept>
#include "include/xntype.h"
#include "include/xnmacros.h"

NS_XNL_BEGIN

class Object {
public:
	Object();
	Object( const Object & p_obj );
	virtual ~Object();
	
	/*
	 * 释放一个引用
	 * 释放后,如果引用计数为0,则会删除对象
	 */
	void release();
	
	/*
	 * 添加一个引用
	 * 将引用计数加1
	 */
	void retain();
	
	/*
	 * 添加对象到自动释放池中
	 */
	void autorelease();
	
	/*
	 * 返回对象被引用的次数
	 */
	XNcount refCount() const;
	
private:
	XNcount m_refcnt; // 此对象的引用计数
	XNbool m_isAutorelease; // 此对象是否加入了自动释放池
	
	friend class AutoreleasePool;
};

NS_XNL_END

#endif /* XNL_OBJECT_CLASS_H_ */
